﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;

namespace Kokomo.IO
{
	public static class IoExtensions
	{
		public static int WriteTo(this Stream source, Stream target, int blockSize)
		{
			ArgumentValidation.CheckNullArgument("source", source);
			ArgumentValidation.CheckNullArgument("target", target);

			byte[] buffer = new byte[blockSize];
			int totalBytesCopied = 0;

			int bytesRead = 0;
			do
			{
				bytesRead = source.Read(buffer, 0, blockSize);
				target.Write(buffer, 0, bytesRead);

				totalBytesCopied += bytesRead;
			} while (bytesRead > 0);

			return totalBytesCopied;
		}
	}
}
